package com.example.figurehecheng.controller.user;


import com.example.figurehecheng.common.result.Result;
import com.example.figurehecheng.domain.vo.NewsVO;
import com.example.figurehecheng.service.INewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 新闻资讯表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-03-04
 */
@RestController("userNewsController")
@RequestMapping("/user/news")
@Api(tags = "用户端-新闻相关接口")
@RequiredArgsConstructor
@CrossOrigin
@Slf4j
public class NewsController {
    @Autowired
    private INewsService newsService;

    /**
     * 查询新闻列表
     * @return
     */
    @GetMapping("/List")
    @ApiOperation("查询新闻列表")
    public Result<List<NewsVO>> ListgetNews(){
           List<NewsVO> newsVOList =newsService.getNewsList();
            return Result.success(newsVOList);
    }
    /**
     * 查询新闻详情
     * @return
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("查询新闻详情")
    public Result<NewsVO> getNewsDetail(@PathVariable("id") Long id){
        NewsVO newsVO = newsService.getNewsDetail(id);
        log.info(String.valueOf(newsVO));
        return Result.success(newsVO);
    }

    /**
     * 根据名称搜索新闻
     * @return
     */
    @GetMapping("/searchByName")
    @ApiOperation("根据名称搜索新闻")
    public Result<List<NewsVO> > searchNewsByName(@RequestParam("name") String name){
        List<NewsVO> newsVOList = newsService.searchNewsByName(name);
        return Result.success(newsVOList);
    }
}
